﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SampleDomainModel;
using Cjc.Data.Mapping;

namespace DataMappingDemo
{
	class Program
	{
		static void Main( string[] args )
		{
			TestQueries( MakeLinqToSqlQueryContext() );
			TestQueries( MakeEntityModelQueryContext() );
		}

		private static void TestQueries( QueryContext context )
		{
			var accounts = context.CreateQuery<Account>();

			var summary = from a in accounts
						  select new
						  {
							  Name = a.Name,
							  Transactions = from t in a.Transactions
											 select new
											 {
												 Payee = t.Payee,
												 Amount = t.Amount
											 }
						  };

			foreach ( var s in summary )
			{
				Console.WriteLine( s.Name );
				foreach ( var t in s.Transactions ) Console.WriteLine( string.Format( "{0} ... {1:C2}", t.Payee, t.Amount ) );
			}
		}

		private static QueryContext MakeLinqToSqlQueryContext()
		{
			return new QueryContext(
				new DataProviderSpecification
				{
					ContextAssembly = "SampleDataModel",
					ContextType = "SampleDataModel.LinqToSql.LinqToSqlDataContext"
				} );
		}

		private static QueryContext MakeEntityModelQueryContext()
		{
			return new QueryContext(
				new DataProviderSpecification
				{
					ContextAssembly = "SampleDataModel",
					ContextType = "SampleDataModel.EntityModel.MyLocalDatabaseEntitiesWrapper"
				} );
		}
	}
}